from django_filters import rest_framework as r_filters
from v1.models import Provincial

class Provincialfilter(r_filters.FilterSet):
    parent  = r_filters.CharFilter(method="get_parent")

    class Meta:
        # model 该类是为Provincial定义的过滤类
        model = Provincial
        # fields该过滤类可以处理Provincial,model中字段parent的查询
        fields = '__all__'

    def get_parent(self, queryset, parent,val):
        print(queryset)
        if val == 'None':
            return queryset.filter(parent=None)
        else:
            return queryset.filter(parent=val)








